#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5+10;
int A[maxn];
int main() {
    ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int T; cin >> T;
    while(T--){
        int N; cin >> N;
        for (int i = 1; i <= N; ++i) {
            cin >> A[i];
        }
        int p = N;
        while(p > 1 && A[p-1] >= A[p]) --p;
        while(p > 1 && A[p-1] <= A[p]) --p;
        cout << p-1 << endl;
    }
    return 0;
}